﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;
using static WinFormsApp1.Leo.week02.TareAdd;

namespace WinFormsApp1.Leo.week02
{
    //分割领用添加
    public partial class SplitRequisAdd : Form
    {
        public SplitRequisAdd()
        {
            InitializeComponent();
            GetUPCData();
            GetProduct();
            GetDepot();
        }

        //仓库
        public async void GetDepot()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<Depotes>>>(URLCommon.Url2, "/Tsw/GetDepottypeData", HttpClientHelper.MethodType.GET, default);

            comboBox1.DataSource = items.Data;
            comboBox1.DisplayMember = "DepotTypeName";
            comboBox1.ValueMember = "DepotTypeId";

            this.Controls.Add(comboBox3);
        }

        public class Depotes
        {
            public int DepotTypeId { get; set; }
            public string DepotTypeName { get; set; }
        }

        //商品代号
        public async void GetUPCData()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<UPCDataser>>>(URLCommon.Url2, "/WeekListOne_Leo/GetUPCDataShow", HttpClientHelper.MethodType.GET, default);

            comboBox3.DataSource = items.Data;
            comboBox3.DisplayMember = "UPCDataName";
            comboBox3.ValueMember = "GoodsMinuteId";

            this.Controls.Add(comboBox3);
        }

        public class UPCDataser
        {
            public int GoodsMinuteId { get; set; }
            public string UPCDataName { get; set; }
        }

        //商品批号
        public async void GetProduct()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<Productser>>>(URLCommon.Url2 ,"/WeekListOne_Leo/GetProductShow", HttpClientHelper.MethodType.GET, default);

            comboBox2.DataSource = items.Data;
            comboBox2.DisplayMember = "ProductName";
            comboBox2.ValueMember = "ProductId";

            this.Controls.Add(comboBox3);
        }

        public class Productser
        {
            public int ProductId { get; set; }
            /// <summary>
            /// 商品批号名称
            /// </summary>
            public string ProductName { get; set; }
        }

        public record Taresa( DateTime SplitRequisTime, int DepotId, int ProductId, int MarkId, string SplitRequisNum, string SplitRequisGrossWeight,
            string SplitRequisTares, string SplitRequisWeight, string SplitRequisRemark, bool IsDelete);

        private async void button1_Click(object sender, EventArgs e)
        {
            var SplitRequisTime =Convert.ToDateTime( dateTimePicker1.Text);
            var DepotId = Convert.ToInt32(comboBox1.SelectedValue);
            var ProductId =Convert.ToInt32(comboBox2.SelectedValue);
            var MarkId = Convert.ToInt32(comboBox3.SelectedValue);
            var SplitRequisNum = textBox1.Text;
            var SplitRequisGrossWeight = textBox2.Text;
            var SplitRequisTares = textBox3.Text;
            var SplitRequisWeight = textBox4.Text;
            var SplitRequisRemark = textBox5.Text;
            var IsDelete = false;



            Taresa clients = new(SplitRequisTime, DepotId, ProductId, MarkId, SplitRequisNum, SplitRequisGrossWeight, SplitRequisTares, SplitRequisWeight, SplitRequisRemark,IsDelete);
            var res = await HttpClientHelper.RequestUrl<Taresa, ApiResult<SplitRequiser>>(URLCommon.Url1, "/WorkList01_leo/GetSplitRequisAdd", HttpClientHelper.MethodType.POST, clients);
            if (res.Code == 1)
            {
                MessageBox.Show("添加成功");
            }
        }

        public class SplitRequiser
        {
            public int SplitRequisId { get; set; }

            /// <summary>
            /// 称重时间
            /// </summary>
            public DateTime? SplitRequisTime { get; set; }

            /// <summary>
            /// 仓库
            /// </summary>
            public int DepotId { get; set; }

            /// <summary>
            /// 商品批号
            /// </summary>
            public int ProductId { get; set; }

            /// <summary>
            /// 商品代号
            /// </summary>
            public int MarkId { get; set; }

            /// <summary>
            /// 件数
            /// </summary>
            public string SplitRequisNum { get; set; }

            /// <summary>
            /// 毛重
            /// </summary>
            public string SplitRequisGrossWeight { get; set; }

            /// <summary>
            /// 皮重
            /// </summary>
            public string SplitRequisTares { get; set; }

            /// <summary>
            /// 净重
            /// </summary>
            public string SplitRequisWeight { get; set; }

            /// <summary>
            /// 备注
            /// </summary>
            public string SplitRequisRemark { get; set; }

            /// <summary>
            /// 是否删除
            /// </summary>
            public bool IsDelete { get; set; } = false;
        }
    }
}
